package com.alit.url.manager;

import com.alit.url.manager.controller.UrlManagerController;
import com.alit.url.manager.model.UrlManager;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UrlManagerApplication extends JFinalConfig {
  public static void main(String[] args) {
    long start = System.currentTimeMillis();
    UndertowServer.start(UrlManagerApplication.class, 80, true);
    long end = System.currentTimeMillis();
    System.out.println("启动完成,共使用了" + (end - start) + "ms");
  }

  public void configConstant(Constants me) {
    me.setDevMode(true);
  }

  public void configRoute(Routes me) {
    me.add("/", UrlManagerController.class);
    boolean mappingSuperClass = me.getMappingSuperClass();
    log.info("mappingSuperClass:" + mappingSuperClass);
  }

  public void configEngine(Engine me) {
  }

  public void configPlugin(Plugins me) {
    PropKit.use("undertow.txt");
    String jdbcUrl = PropKit.get("jdbc.url");
    String jdbcUser = PropKit.get("jdbc.user");
    String jdbcPswd = PropKit.get("jdbc.pswd");
    DruidPlugin dp = new DruidPlugin(jdbcUrl, jdbcUser, jdbcPswd);
    dp.start();
    me.add(dp);
    ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
    me.add(arp);
    arp.start();
    arp.addMapping("url_manager", UrlManager.class);

  }

  public void configInterceptor(Interceptors me) {
  }

  public void configHandler(Handlers me) {
  }
}